/*
 * Copyright (c) 2022.版权所有高金磊
 */

package 领扣算法.A简单题.完成一半题目;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;

public class Main {
    public int halfQuestions(int[] questions) {
        HashMap<Integer,Integer> data=new HashMap<>();
        for (int question : questions) {
            data.put(question, data.getOrDefault(question, 0)+1);
        }
        LinkedList<Integer> arrayList=new LinkedList<>(data.values());
        Collections.sort(arrayList, (a,b)->(b-a));
        int res=0;
        int count=0;
        while (count<(questions.length)/2){
            count+=arrayList.pollFirst();
            res++;
        }
        return res;
    }
}
